package kr.moiba.vertification.service.iimpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import kr.moiba.vertification.dao.VertificationDao;
import kr.moiba.vertification.dao.VertificationHistoryDao;
import kr.moiba.vertification.domain.Vertification;
import kr.moiba.vertification.service.VertificationSvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Lee Youngho
 *
 */

@Service
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT ,rollbackFor = {Exception.class} ,readOnly = false)
public class VertificationSvcImpl implements VertificationSvc {

	@Autowired
	VertificationDao vertificationDao;
	
	@Autowired
	VertificationHistoryDao vertificationHistoryDao;
	
	public VertificationSvcImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<Vertification> findbyList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		return (List<Vertification>) (vertificationDao.SelectList(condition));
	}

	public Map<String, Object> findbyListPaging(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("vertificationList", (List<Vertification>) (vertificationDao.SelectList(condition)));
		resultMap.put("vertificationListTotalCnt", (Integer) (vertificationDao.SelectListTotalCnt(condition)));
		
		return resultMap;
	}
	
	@Override
	public List<Map<String, Object>> findbyListResult(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		return vertificationDao.SelectListResult(condition);
	}

	@Override
	public Vertification findby(Integer idx) throws Exception {
		// TODO Auto-generated method stub
		return vertificationDao.select(idx);
	}

	@Override
	public Vertification add(Vertification vertification) throws Exception {
		// TODO Auto-generated method stub
		Vertification result = vertificationDao.insert(vertification);
		return result;
	}

	@Override
	public Vertification modify(Vertification vertification) throws Exception {
		// TODO Auto-generated method stub
		
		//history 등록
		vertificationHistoryDao.insert(vertification.getIdx());
		
		return vertificationDao.update(vertification);
	}

	@Override
	public int remove(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		return vertificationDao.delete(condition);
	}
	
	@Override
	public List<Vertification> findbyListHistory(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		return (List<Vertification>) (vertificationHistoryDao.SelectList(condition));
	}

}